package com.day1;

import javax.servlet.ServletException;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class fail extends HttpServlet{
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //super.service(req, resp);
//        resp.setContentType("text/html;charset=utf-8");
//        String name = req.getParameter("username");
//        String psw = req.getParameter("psw");
//        resp.getWriter().print("用户名：<input type=\"text\" name=\"username\" />\n"+"<br />" +
//                    "        密码：<input type=\"password\" name=\"psw\"/><br />\n" +
//                    "        <input type=\"submit\" />");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        Cookie[] reqCookies = req.getCookies();
        if (reqCookies==null){
            for (Cookie rck:reqCookies){
                if ("name".equals(rck.getName())){
                    req.setAttribute("name",rck.getValue());
                    req.getRequestDispatcher("success").forward(req,resp);
                }
            }
        }

        Object name = req.getAttribute("name");
        System.out.println("name="+name);
        //登陆界面
        resp.getWriter().print("<form action=\"/hhh/User\" method=\"post\">" +
                "        用户名: <input type=\"text\" name=\"username\"/> <span style='color:red'>"
                +"</span><br />" +
                "        密码：<input type=\"password\" name=\"password\"/><br /><input type=\"submit\"/>" +
                "    </form>");
    }
}
